package view;

import javax.swing.JFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;

import com.toedter.calendar.JCalendar;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Date;

public class MyDatePicker extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1235210794134748605L;
	public static Date sDate;
	private JCalendar calendarPanel;
	public MyDatePicker() {
		setTitle("Pickup a day");
		JButton btnOk = new JButton("OK");
		btnOk.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				sDate = calendarPanel.getDate();
				setVisible(false);
				dispose();
			}
		});
		
		calendarPanel = new JCalendar();
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addComponent(calendarPanel, GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE)
						.addComponent(btnOk))
					.addContainerGap())
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(calendarPanel, GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(btnOk)
					.addContainerGap())
		);
		getContentPane().setLayout(groupLayout);
	}
	public void setDate(Date new_date){
		sDate = new_date;
		calendarPanel.setDate(sDate);
	}
}
